<template>
  <div class="qualification-container">
    <el-card class="qualification-card">
      <template #header>
        <div class="card-header">
          <span class="title">司机资质认证</span>
          <el-tag :type="info.status === 1 ? 'success' : 'info'" size="large">
            {{ info.status === 1 ? '已认证' : '未认证' }}
          </el-tag>
        </div>
      </template>
      
      <div v-loading="loading">
        <!-- 基本信息 -->
        <div class="section">
          <div class="section-title">
            <el-icon><User /></el-icon>
            <span>基本信息</span>
      </div>
          <el-row :gutter="20">
            <el-col :span="8">
              <div class="info-item">
                <div class="label">姓名</div>
                <div class="value">{{ info.realName }}</div>
              </div>
            </el-col>
            <el-col :span="8">
              <div class="info-item">
                <div class="label">身份证号</div>
                <div class="value">{{ info.idCardNumber }}</div>
              </div>
            </el-col>
            <el-col :span="8">
              <div class="info-item">
                <div class="label">认证时间</div>
                <div class="value">{{ info.createTime }}</div>
              </div>
            </el-col>
          </el-row>
        </div>

        <!-- 证件照片 -->
        <div class="section">
          <div class="section-title">
            <el-icon><Document /></el-icon>
            <span>证件照片</span>
          </div>
          <el-row :gutter="20">
            <el-col :span="8">
              <div class="image-card">
                <div class="image-title">身份证正面</div>
                <el-image 
                  :src="info.idCardFrontUrl" 
                  fit="cover"
                  :preview-src-list="[info.idCardFrontUrl]"
                />
              </div>
            </el-col>
            <el-col :span="8">
              <div class="image-card">
                <div class="image-title">身份证反面</div>
                <el-image 
                  :src="info.idCardBackUrl" 
                  fit="cover"
                  :preview-src-list="[info.idCardBackUrl]"
                />
              </div>
            </el-col>
            <el-col :span="8">
              <div class="image-card">
                <div class="image-title">驾驶证</div>
                <el-image 
                  :src="info.drivingLicenseUrl" 
                  fit="cover"
                  :preview-src-list="[info.drivingLicenseUrl]"
                />
              </div>
            </el-col>
          </el-row>
        </div>
        
        <!-- 车辆信息 -->
        <div class="section">
          <div class="section-title">
            <el-icon><Van /></el-icon>
            <span>车辆信息</span>
          </div>
          <el-row :gutter="20">
            <el-col :span="8">
              <div class="info-item">
                <div class="label">车牌号</div>
                <div class="value">{{ info.vehicleNumber }}</div>
              </div>
            </el-col>
            <el-col :span="8">
              <div class="info-item">
                <div class="label">车辆品牌</div>
                <div class="value">{{ info.vehicleBrand }}</div>
              </div>
            </el-col>
            <el-col :span="8">
              <div class="info-item">
                <div class="label">车辆型号</div>
                <div class="value">{{ info.vehicleModel }}</div>
              </div>
            </el-col>
            <el-col :span="8">
              <div class="info-item">
                <div class="label">车辆颜色</div>
                <div class="value">{{ info.vehicleColor }}</div>
              </div>
            </el-col>
          </el-row>
          <el-row :gutter="20" class="mt-20">
            <el-col :span="12">
              <div class="image-card">
                <div class="image-title">车辆照片</div>
                <el-image 
                  :src="info.vehiclePhotoUrl" 
                  fit="cover"
                  :preview-src-list="[info.vehiclePhotoUrl]"
                />
              </div>
            </el-col>
            <el-col :span="12">
              <div class="image-card">
                <div class="image-title">行驶证</div>
                <el-image 
                  :src="info.vehiclePermitUrl" 
                  fit="cover"
                  :preview-src-list="[info.vehiclePermitUrl]"
                />
              </div>
            </el-col>
          </el-row>
        </div>
      </div>
    </el-card>
  </div>
</template>

<script setup>
import { ref, onMounted } from 'vue'
import { ElMessage } from 'element-plus'
import { getDriverInfo } from '@/api/user'
import { User, Document, Van } from '@element-plus/icons-vue'

// 数据定义
const loading = ref(false)
const info = ref({
  realName: '',
  idCardNumber: '',
  idCardFrontUrl: '',
  idCardBackUrl: '',
  drivingLicenseNumber: '',
  drivingLicenseUrl: '',
  vehicleNumber: '',
  vehicleBrand: '',
  vehicleModel: '',
  vehicleColor: '',
  vehiclePhotoUrl: '',
  vehiclePermitUrl: '',
  status: 0,
  createTime: '',
  updateTime: ''
})

// 获取认证信息
const fetchDriverInfo = async () => {
  loading.value = true
  try {
    const res = await getDriverInfo()
    if (res.code === 1) {
      info.value = res.data
    } else {
      ElMessage.error(res.msg || '获取认证信息失败')
    }
  } catch (error) {
    console.error('获取认证信息失败：', error)
    ElMessage.error('获取认证信息失败')
  } finally {
    loading.value = false
  }
}

// 页面加载时获取认证信息
onMounted(() => {
  fetchDriverInfo()
})
</script>

<style scoped>
.qualification-container {
  padding: 20px;
}

.qualification-card {
  max-width: 1200px;
  margin: 0 auto;
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.title {
  font-size: 16px;
  font-weight: bold;
}

.section {
  margin-bottom: 30px;
}

.section-title {
  display: flex;
  align-items: center;
  margin-bottom: 20px;
  font-size: 16px;
  font-weight: bold;
  color: #303133;
}

.section-title .el-icon {
  margin-right: 8px;
  font-size: 18px;
}

.info-item {
  margin-bottom: 15px;
}

.info-item .label {
  color: #909399;
  font-size: 14px;
  margin-bottom: 5px;
}

.info-item .value {
  color: #303133;
  font-size: 14px;
}

.image-card {
  border: 1px solid #EBEEF5;
  border-radius: 4px;
  overflow: hidden;
  margin-bottom: 20px;
}

.image-title {
  background-color: #F5F7FA;
  padding: 8px 12px;
  font-size: 14px;
  color: #606266;
  border-bottom: 1px solid #EBEEF5;
}

.el-image {
  width: 100%;
  height: 200px;
  display: block;
}

.mt-20 {
  margin-top: 20px;
}

:deep(.el-card__header) {
  padding: 15px 20px;
  border-bottom: 1px solid #EBEEF5;
}

:deep(.el-card__body) {
  padding: 20px;
}
</style> 